home *** CD-ROM | disk | FTP | other *** search
/ Gigarom 1 / Gigarom Macintosh Archives (Quantum Leap)(CDRM1080320)(1993).iso / FILES / BBS / MUBBS / MUBBS etc.cpt / Module Source / Caller Module code / Caller Module.c next >
Text File  |  1991-11-14  |  3KB  |  98 lines

  1. /*
  2.  *  Caller Module.c
  3.  *
  4.  *    This program source code and it's compiled version is
  5.  *  Copyright (c) 1991 N. Hawthorn.
  6.  *  This program source code and it's compiled version IS NOT IN THE
  7.  *  PUBLIC DOMAIN ! Please read the "COPYRIGHT NOTICE / NH" file for details
  8.  *  regarding use of this program source code and it's compiled version.
  9.  *
  10.  *  This module's name is "maincaller", it's type is "MOD1", it's ID is 128
  11.  *  because we know the menu module's ID is 131. Normally a resource mover
  12.  *  would assign a new number to it, that's why we name our modules !
  13.  *
  14.  *  This is where it all starts...
  15.  *
  16.  */
  17.  
  18. #define INMAIN
  19.  
  20. #include     <SetUpA4.h>
  21. #include    "MUBBS Module.h"
  22.  
  23. /* my globals for this module */
  24.  
  25.  
  26. pascal void main (mode1,G1,P1)
  27.        int mode1;
  28.        struct GS *G1;
  29.        Ptr *P1; /* we ignore "P" in this module */
  30. {
  31. Handle temph;
  32. float version = 0.5; /* what version of MUBBS you are compatable with IE: .5 and above */
  33. RememberA0(); SetUpA4(); /* This sets up the A4 register to access our globals */
  34. asm { _RecoverHandle }; asm {move.l a0,temph}; HLock(temph); /* locks our module, do this ! */
  35.  
  36. G=G1; /* This MUST be the first thing you do in main only, it sets up the struct globals */
  37. mode[u]=mode1; /* set up our mode so that you can read it anywhere */
  38.  
  39. switch (mode[u]) { /* any un-handled modes return error from this module */
  40.     case 2:
  41.         callthem();
  42.         G->moduleresult=0;
  43.         break;
  44.     case 98:
  45.         versionck(version); /* just return after this call, don't modify anything */
  46.         break;        
  47.     case 0:
  48.         strcpy (G->programmer,"N Hawthorn"); /* show the programmer's name up to 20 chars*/
  49.         G->moduleresult=0; /* this was also a init call if we need close call put 99 here */
  50.         break;
  51.     default:
  52.         G->moduleresult=1; /* return bad code */
  53.     };
  54.  
  55. HUnlock(temph); /* unlocks this module, do this ! */
  56. RestoreA4(); /* call this when you are all done */
  57. }
  58.  
  59. callthem() /* call a list of modules in order */
  60. {
  61. FILE *stream;
  62. char tocall[21][28]; /* takes up about 1K of stack space, module names not over 26 chars */
  63. char filename[64];
  64. int i,x;
  65.  
  66. if (!G->online[u]) return; /* do this check so we can log out if hang up */
  67.  
  68. /* Generate the filename */
  69. strcpy(filename,":caller:");
  70. strcat(filename,G->modulename[u]);
  71. strcat(filename,".info");
  72.  
  73. if ((stream = fopen(filename, "r")) == NULL) { /* Open the file */
  74.     send("]FILE ERROR cannot open %s ]", filename);
  75.     return;
  76.     }
  77. else    /* If no error, read from the file */
  78.     {
  79.                     
  80.     i = 0;
  81.     while (i < 20){
  82.         if (fscanf(stream,"%27[^\n]\n",tocall[i]) == EOF) break; /* end on EOF */
  83.         i++;
  84.         }
  85.     fclose(stream); /* always close the file even if empty */
  86.     }
  87.  
  88.     if (i==0) return; /* exit if file empty */
  89.  
  90.     for (x = 0; x<i; x++) /* Launch the modules */
  91.         {
  92.         module(2,tocall[x],0L);
  93.         if (!G->online[u]) return; /* do this check so we can log out if hang up */
  94.         }
  95. }
  96.  
  97.  
  98.